package com.kaka.service.serviceimpl;

import com.kaka.dao.AdminDao;
import com.kaka.dao.StudentDao;
import com.kaka.dao.TeacherDao;
import com.kaka.dao.daoimpl.AdminDaoImpl;
import com.kaka.dao.daoimpl.StudentDaoImpl;
import com.kaka.dao.daoimpl.TeacherDaoImpl;
import com.kaka.bean.Admin;
import com.kaka.bean.Student;
import com.kaka.bean.Teacher;
import com.kaka.service.MainService;

import java.util.List;

public class MainServiceImpl implements MainService {

    private final StudentDao studentDao = new StudentDaoImpl();
    private final TeacherDao teacherDao = new TeacherDaoImpl();
    private final AdminDao adminDao = new AdminDaoImpl();

    @Override
    public Student studentLogin(String username, String password) {
        List<Student> studentList = studentDao.selectByUsernameAndPassword(username, password);
        if (studentList.isEmpty())
            return null;
        else
            return studentList.get(0);
    }

    @Override
    public Teacher teacherLogin(String username, String password) {
        List<Teacher> teacherList = teacherDao.selectByUsernameAndPassword(username, password);
        if (teacherList.isEmpty())
            return null;
        else
            return teacherList.get(0);
    }

    @Override
    public Admin adminLogin(String username, String password) {
        List<Admin> adminList = adminDao.selectByUsernameAndPassword(username, password);
        if (adminList.isEmpty())
            return null;
        else
            return adminList.get(0);
    }
}
